# -*- coding: utf-8 -*-
from django.db import models

# Create your models here.
from django.contrib import admin
from django.contrib.auth.models import User
import django.utils.timezone as timezone
# import sys
# reload(sys)
# sys.setdefaultencoding('utf8')


# 单选题：题库 by hcq
class SingleProblem(models.Model):
    #PrimaryID为在所有SingleProblem中所处的位置ID
    PrimaryID = models.IntegerField(primary_key = True,verbose_name = u'单选题ID')
    ExamID = models.CharField(max_length = 40,verbose_name = u'试卷ID')
    #SingleProblemID为在当前试卷中所处的位置ID
    SingleProblemID = models.IntegerField(max_length = 50,verbose_name = u'当前试卷中单选题ID')
    CourseID = models.CharField(max_length = 20,verbose_name = u'课程ID')
    SingleTitle = models.CharField(max_length = 2000,verbose_name = u'题目')
    OptionA = models.CharField(max_length = 1000,verbose_name = u'选项A')
    OptionB = models.CharField(max_length = 1000,verbose_name = u'选项B')
    OptionC = models.CharField(max_length = 1000,verbose_name = u'选项C')
    OptionD = models.CharField(max_length = 1000,verbose_name = u'选项D')
    SingleAnswer = models.CharField(max_length = 10, verbose_name = u'答案')
    weight = models.CharField(max_length = 10, verbose_name = u'分值')

    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return  self.CourseID + '_' + self.ExamID + '_' +str(self.SingleProblemID)

##出题
class Course(models.Model):
    # CourseID = 001 002 003 ...
    CourseID = models.CharField(primary_key = True, max_length = 10, verbose_name = u'课程ID')
    CourseName = models.CharField(max_length = 100, verbose_name = u'课程名称')

    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return self.CourseID + '_' + self.CourseName


# ##建议删除
# class Student(models.Model):
#     StudentID = models.IntegerField(primary_key = True,verbose_name = u'学生ID')
#     StudentName = models.CharField(max_length = 20,verbose_name = u'学生姓名')
#     GENDER_CHOICES = ((True,'男性'),(False,'女性'))
#     StudentGender = models.NullBooleanField(choices = GENDER_CHOICES,verbose_name = u'性别')
#     StudentAge = models.IntegerField (verbose_name = u'年龄')
#     StudentPassword = models.CharField(max_length = 30,verbose_name = u'密码')
#     StudentEmail = models.EmailField(verbose_name = u'Email')

#     def __unicode__(self):
#         return self.StudentID + '_' + self.StudentName


# ##建议删除
# class Teacher(models.Model):
#     TeacherID = models.IntegerField(primary_key = True,verbose_name = u'教师ID')
#     TeacherName = models.CharField(max_length = 20,verbose_name = u'教师姓名')
#     GENDER_CHOICES = ((True,'男性'),(False,'女性'))
#     TeacherGender = models.NullBooleanField(choices = GENDER_CHOICES,verbose_name = u'性别')
#     TeacherAge = models.IntegerField(verbose_name = u'年龄')
#     TeacherPassword = models.CharField(max_length = 30,verbose_name = u'密码')
#     TeacherEmail = models.EmailField(verbose_name = u'Email')

#     def __unicode__(self):
#         return self.TeacherID + '_' + self.TeacherName

# 试卷信息表 by hcq
class ExamPaperInfo(models.Model):
    # ExamID 统一使用当前时间为值，例如：2017_4_2_21_46
    ExamID = models.CharField(primary_key = True, max_length = 40,verbose_name = u'试卷编号')
    ExamName = models.CharField(max_length = 100, verbose_name = u'试卷名')
    ExamQuestions = models.CharField(max_length = 2000, verbose_name = u'试卷题目')
    CourseID = models.CharField(max_length = 100, verbose_name = u'课程ID')
    ExamTime = models.CharField(max_length = 10, verbose_name = u'考试时长(min)')
    ProblemNum = models.CharField(max_length = 10, verbose_name = u'题量', null = True)
    TotalScore = models.IntegerField(verbose_name = u'总分')
    TeacherID = models.IntegerField(verbose_name = u'出题者编号')

    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')
    #ExamState = models.IntegerField(verbose_name = u'试卷状态')
    #ExamType = models.IntegerField(verbose_name = u'试卷类型')

    def __unicode__(self):
        return self.ExamID + self.ExamName


# ##不是很懂
# class ExamPaperDetailOfQuestion(models.Model):
#     ExamID = models.IntegerField(verbose_name = u'试卷ID')
#     QustionID = models.IntegerField(verbose_name = u'题目ID')
#     QustionType = models.CharField(max_length = 10,verbose_name = u'题目类型')
#     QustionOrder = models.IntegerField(verbose_name = '序号')
#     QustionScore = models.IntegerField(verbose_name = '分数')

#     def __unicode__(self):
#         return '题目' + self.QuestionID


# ##不是很懂
# class ExamPaperTypeOfQuestion(models.Model):
#     ExamID = models.IntegerField(verbose_name = u'试卷ID')
#     TypeOrder = models.IntegerField(verbose_name = u'题目顺序')
#     QustionType = models.CharField(max_length = 10,verbose_name = u'题目类型')
#     TypeNum = models.IntegerField(verbose_name = u'此题型数量')
#     TypeScore = models.IntegerField(verbose_name = u'此题型总分')

#     def __unicode__(self):
#         return '试卷问题类型' + id

# class ExamPaperDetailOfAnswered(models.Model):
#     AnsweredID = models.IntegerField(verbose_name = '作答ID')
#     QuestionID = models.IntegerField(verbose_name = '题目ID')
#     QustionType = models.CharField(max_length = 10,verbose_name = u'题目类型')  ##感觉没用
#     StuAnswer = models.CharField(max_length = 10,verbose_name = u'学生答案')
#     StandardAnswer = models.CharField(max_length = 10,verbose_name = u'标准答案')
#     QuestionScore = models.IntegerField(verbose_name = '此题分数')
#     StuScore = models.IntegerField(verbose_name = '此题得分')

#     def __unicode__(self):
#         return '作答详情' + id

# class ExamPaperAnsweredInfo(models.Model):
#     AnsweredID = models.IntegerField(primary_key = True,verbose_name = '作答ID')
#     ExamID = models.IntegerField(verbose_name = '试卷ID')
#     StudentID = models.IntegerField(verbose_name = '学生ID')
#     ExamState = models.IntegerField(verbose_name = u'试卷状态')
#     TotalMark = models.IntegerField(verbose_name = '作答总分')

#     def __unicode__(self):
#         return '作答' + self.AnsweredID

# 成绩表
class ScoreInfo(models.Model):
    StuID = models.CharField(max_length = 20, verbose_name = u'学生ID')
    ExamID = models.CharField(max_length = 40, verbose_name = u'试卷编号')
    Score = models.CharField(max_length = 10, verbose_name = u'考生成绩')
    ExamState = models.IntegerField(default = False, verbose_name = u'试卷状态')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    # 多个主键
    class Meta:
        unique_together = ('StuID', 'ExamID')

    def __unicode__(self):
        return self.StuID + '__' + self.ExamID + '__' + self.Score

